"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global sessionStorage, PbxApi */

/**
 * Object responsible for sending PBX metrics.
 *
 * @module sendMetrics
 */
var sendMetrics = {
  /**
   * Initializes the send metrics functionality by checking if metrics have already been sent.
   * If metrics have not been sent, it sends the metrics.
   */
  initialize: function initialize() {
    var isMetricsSend = sessionStorage.getItem('MetricsAlreadySent');

    if (isMetricsSend === null) {
      PbxApi.LicenseSendPBXMetrics(sendMetrics.cbAfterMetricsSent);
    }
  },

  /**
   * Callback function after metrics have been sent.
   * @param {boolean} result - The result of sending the metrics.
   */
  cbAfterMetricsSent: function cbAfterMetricsSent(result) {
    if (result === true) {
      sessionStorage.setItem('MetricsAlreadySent', 'true');
    }
  }
};
/**
 * Sends PBX metrics on document ready.
 */

$(document).ready(function () {
  sendMetrics.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9TZW5kTWV0cmljcy9zZW5kLW1ldHJpY3MtaW5kZXguanMiXSwibmFtZXMiOlsic2VuZE1ldHJpY3MiLCJpbml0aWFsaXplIiwiaXNNZXRyaWNzU2VuZCIsInNlc3Npb25TdG9yYWdlIiwiZ2V0SXRlbSIsIlBieEFwaSIsIkxpY2Vuc2VTZW5kUEJYTWV0cmljcyIsImNiQWZ0ZXJNZXRyaWNzU2VudCIsInJlc3VsdCIsInNldEl0ZW0iLCIkIiwiZG9jdW1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